/**
 * Created by xinguoren on 15-4-17.
 */
var userService = require("../services/userService");
var mongoService = require("../services/mongoService");
exports.login = function(req, res){
    var data = req.body;
    if(!data.name || !data.password){
        res.end("");
    }
    userService.login(data, function(back){
        console.log("loging bak", back);
        if(back.error){
            res.end(back.msg);
        }else{
            req.session.user = back[0];
            res.end("success");
        }
    });
    console.log("login data",data);

};
exports.sign = function(req, res){
    var data = req.body;
    if(!data.name || !data.password){
        return res.end("");
    }
    data.id = (new Date()).getTime();
    userService.sign(data, function(back){
        if(back.error){
            res.end("服务器错误");
        }else if(back.already){
            res.end("用户名已存在");
        }else{
            req.session.user = data[0];
            res.end("success");
        }
    });
};